package com.suyl.candy.impexcel.service.impl;

import com.suyl.candy.impexcel.entity.Money;
import com.suyl.candy.impexcel.service.IMoney;
import com.suyl.candy.impexcel.utils.DateUtils;
import com.suyl.candy.model.entity.BussAccount;
import com.suyl.candy.model.service.BussAccountService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * 用户人员实现类
 *
 * @author fraser
 * @date 2019/10/7 2:02 PM
 */
@Service
@Slf4j
public class MoneyServiceImpl implements IMoney {

    @Autowired
    BussAccountService bussAccountService;

    @Override
    public boolean saveData(List<Money> monies) {
        log.info("MoneyServiceImpl {}条数据，开始存储数据库！", monies.size());
//        log.info(JSON.toJSONString(monies));
        List<BussAccount> bussAccounts = new ArrayList<>();
        for (Money money : monies) {
            BussAccount bussAccount = new BussAccount();
            bussAccount.setCreateTime(LocalDateTime.now()); // 创建时间
            bussAccount.setCreateUser(1993L);
            bussAccount.setDate(DateUtils.dateToLocalDate(money.getDate()));
            log.info(DateUtils.dateToLocalDate(money.getDate()).toString());
            bussAccount.setWeek(DateUtils.dateToWeek(money.getDate()));
            bussAccount.setCatgroy(money.getCatgroy());
            bussAccount.setName(money.getName());
            bussAccount.setType(money.getType());
            bussAccount.setProject(money.getProject());
            bussAccount.setMoney(money.getMoney());
            bussAccount.setRemarks(money.getRemark());
            bussAccount.setDelFlag("1");
            bussAccounts.add(bussAccount);
        }
        bussAccountService.saveBatch(bussAccounts);
        log.info("MoneyServiceImpl 存储数据库成功！");
        return true;
    }
}
